//
// Created by Tan Ke on 2023/12/22.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmpFunc(const void* ptr1, const void* ptr2)
{
    int* val1 = (int*) ptr1;
    int* val2 = (int*) ptr2;

    return *val1 - *val2;
}

int* numMovesStones(int a, int b, int c, int* returnSize)
{
    int* result = (int*)malloc(sizeof(int) * 2);
    int nums[3] = {0};
    *returnSize = 2;

    int maxXtoY = 0;
    int minXtoY = 0;
    int maxZtoY = 0;
    int minZtoY = 0;

    nums[0] = a;
    nums[1] = b;
    nums[2] = c;

    qsort(nums, 3, sizeof(int), cmpFunc);

    if (nums[1] - nums[0] > 1) {
        maxXtoY = nums[1] - nums[0] - 1;
        minXtoY = 1;
    } else {
        maxXtoY = 0;
        minXtoY = 0;
    }

    if (nums[2] - nums[1] > 1) {
        maxZtoY = nums[2] - nums[1] - 1;
        minZtoY = 1;
    } else {
        maxZtoY = 0;
        minZtoY = 0;
    }

    result[0] = minXtoY + minZtoY;
    result[1] = maxXtoY + maxZtoY;

    return result;
}

int main(void)
{
    int size;
    int *result = numMovesStones(3, 5, 1, &size);
    printf("%d, %d\n", result[0], result[1]);

    return 0;
}

